/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package im.messages;

//import jade.domain.introspection.ACLMessage;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.UnreadableException;
import java.io.IOException;
import java.io.Serializable;

/**
 *
 * @author brownstone
 */
public class BaseMessage extends ACLMessage {
    public static final int
            NOTIFY = 0,
            PUBLISH = 1,
            JOIN_SERVICE_REQUEST = 2,
            NOTIFY_JOIN = 3,
            NOTIFY_UNJOIN = 4,
            NOTIFY_CH_SHRINKING = 5,
            NOTIFY_CLUSTER_SHRINKING = 6,
            STATUS_REQUEST = 7,
            STATUS_NOTIFY = 8,
            SUBSCRIBE = 9,
            GET_CH_LIST = 10;
            ;

    private static final String[] performatives = new String[22];
	static { // initialization of the Vector of performatives
		performatives[NOTIFY]="NOTIFY";
		performatives[PUBLISH]="PUBLISH";
        performatives[JOIN_SERVICE_REQUEST]="JOIN_SERVICE_REQUEST";
        performatives[NOTIFY_JOIN]="NOTIFY_JOIN";
        performatives[NOTIFY_UNJOIN]="NOTIFY_UNJOIN";
        performatives[NOTIFY_CH_SHRINKING]="NOTIFY_CH_SHRINKING";
        performatives[NOTIFY_CLUSTER_SHRINKING]="NOTIFY_CLUSTER_SHRINKING";
        performatives[STATUS_REQUEST]="STATUS_REQUEST";
        performatives[STATUS_NOTIFY]="STATUS_NOTIFY";
        performatives[SUBSCRIBE]="SUBSCRIBE";
    }

    public BaseMessage(int performative) {
        super(performative);
    }

    public void setMessagePayload(Serializable s) {
        try {
            this.setContentObject(s);
        } catch (IOException ex) {
            System.out.println("errore set payload");
        }
    }

    public Serializable getMessagePayload() {
        try {
            return this.getContentObject();
        } catch (UnreadableException ex) {
            System.out.println("errore get payload");
        }
        return null;
    }
}